package com.logistic.service.impl;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.logistic.common.UidGeneratorByRule;
import com.logistic.dao.IntegralDao;
import com.logistic.dao.UserDao;
import com.logistic.domain.Article;
import com.logistic.domain.ConsumeRecord;
import com.logistic.domain.User;
import com.logistic.page.QueryResult;
import com.logistic.service.UserService;


@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	
	/**
	 * 登录验证
	 * @param user
	 * @return
	 */
	public User checkLogin(User user) {
		User newUser = userDao.login(user);
		if(newUser == null) {
			return null;
		} else {
			return newUser;
		}
	}
	
	public List findRecordAll(String sort)
	{
		List list = new ArrayList();
		list = userDao.getAll();
		return list;
	}
	
	public String save(User user)
	{
		int num = userDao.save(user);
		if(num > 0) {
			return "ok";
		} else {
			return "error";
		}
	}
	
	public void modify(User user)
	{
		userDao.modify(user);
	}
	
	public User getUserByUid(User user){
		return userDao.getUserByUid(user);
	}
	public User getUserByUreceiveId(User user){
		return userDao.getUserByUreceiveId(user);
	}
	
	public void deleteByIdStr(String idStr){
		String[] ids = idStr.split("'"); 
		for(int i = 0; i < ids.length; i++) {
			userDao.delete(ids[i]);
		}
	}
	
	public void changePassword(User user, String pass){
		userDao.changePassword(user,pass);
	}
	
	public boolean checkEmailExist(String email){
		return userDao.checkEmailExist(email);
	}
	public boolean checkUreceveIdExist(String uId){
		return userDao.checkUreceveIdExist(uId);
	}
	
	public boolean checkUidExist(String uId){
		return userDao.checkUidExist(uId);
	}
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
		
	}
	
	public int createChargeRecord(ConsumeRecord record) {
		return userDao.createChargeRecord(record);
	}

	public ConsumeRecord getChargeRecord(String id) {
		return userDao.getChargeRecord(id);
	}
	
	public void updateChargeRecord(String id, String flag) {
		 userDao.updateChargeRecord(id, flag);
	}
	
	public QueryResult showConsumptionHistory(String Uid,int first,int max, String action) {
		return userDao.showConsumptionHistory(Uid, first, max, action);
	}
	
	public void createArticle(Article article) {
		userDao.createArticle(article);
	}
	
	public List getArticle(String type, int count) {
		return userDao.getArticle(type, count);
	}
}
